package com.sy.core.intercepter;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

/**
 * 登录拦截器 配置类
 */
@Configuration
public class MyInterceptorConfig implements WebMvcConfigurer {

    /**
     * 定义放行路径
     */
    public static List<String> EXCLUDE_PATH =
                    Arrays.asList("/**/zTree/**", "/**/css/**","/**/js/**","/aliOSS/fileUpload"
                            ,"/**/fonts/**", "/**/images/**", "/**/layui/**","/**/toastr/**",
                            "/files/**", "/website/*","/register/*","/","/returnPay/**"
                            ,"/user/login", "/back/login","/back/loginout");

    @Bean
    public LoginIntercepter getLoginIntercepter() {
        return new LoginIntercepter();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getLoginIntercepter())
                .addPathPatterns("/**")
                .excludePathPatterns(EXCLUDE_PATH);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/website/home");
    }
}